package com.by.service.impl;
import com.by.bean.Sgoods;
import com.by.common.core.crud.BaseServiceImpl;
import com.by.mapper.SgoodsMapper;
import com.by.mapper.SspecsMapper;
import com.by.service.SgoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class SgoodsServiceimpl extends BaseServiceImpl<Sgoods, SgoodsMapper> implements SgoodsService {
    @Autowired
    SgoodsMapper sm;
    @Autowired
    SspecsMapper spm;
    @Override
    @Transactional
    public int saveEntity(Sgoods entity) {
        int re=sm.insert(entity);
        if (re>0){
         re = spm.insert(entity.getSspecsList(),entity.getId());
        }
        return re;
    }
    @Override
    public List<Map> querylistbyid(int id) {
        return sm.querybylist(id);
    }

    @Override
    public int updateEntity(Sgoods entity) {
           int re=sm.updateEntity(entity);
         if (re>0){
             re=spm.deleteById(entity.getId());
             if (re>0){
                 re=spm.insert(entity.getSspecsList(),entity.getId());
             }
         }
        return re;
    }
}
